package servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dominio.Cotizacion;

import services.CotizacionService;
import services.impl.CotizacionServiceImpl;

/**
 * Servlet implementation class BuscarServlet
 */
public class BuscarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BuscarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		CotizacionService cotService = CotizacionServiceImpl.getInstancia();
		
		Integer cotizacionID = Integer.parseInt(request.getParameter("cotizacionID"));
		Cotizacion cotizacion = cotService.findByID(cotizacionID);
		
		request.setAttribute("cotizacion", cotizacion);
		request.setAttribute("cantItems", cotizacion.getItems().size());
		request.getRequestDispatcher("aceptarCotizacion.jsp").forward(request, response);
	}

}
